package org.ddl.core.strategy.mod;

import org.ddl.core.entity.DataSourceTable;
import org.ddl.core.strategy.TableShardStrategy;

/**
 * 分表取模算法
 * 
 * @author yinjianwei
 * @date Oct 8, 2017 9:34:45 PM
 *
 */
public class ModTableShardStrategy implements TableShardStrategy {

	@Override
	public String getShardType() {
		return "mod";
	}

	@Override
	public DataSourceTable handle(String logicTable, int tableShardNum, Long shardValue) {
		long tablePosition = shardValue % tableShardNum;
		String finalTableName = new StringBuilder().append(logicTable).append(tablePosition).toString();
		return new DataSourceTable("", finalTableName);
	}

}
